package org.dromara.hotel.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.dromara.hotel.domain.TerPriceCalendar;
import org.dromara.hotel.domain.vo.TerPriceCalendarVo;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

/**
 * 酒店日历价格Mapper接口
 *
 * @author xch
 * @date 2025-06-10
 */
public interface TerPriceCalendarMapper extends BaseMapperPlus<TerPriceCalendar, TerPriceCalendarVo> {
    // 批量插入
    @Insert("<script>" +
        "INSERT INTO ter_price_calendar (id, room_id, price_day, final_price, source,available_quantity,version) VALUES " +
        "<foreach collection='list' item='item' separator=','>" +
        "(#{item.id}, #{item.roomId}, #{item.priceDay}, #{item.finalPrice}, #{item.source}, #{item.availableQuantity},1)" +
        "</foreach>" +
        "</script>")
    int batchInsert(@Param("list") List<TerPriceCalendar> list);
    @Transactional
    @Update("TRUNCATE TABLE ter_price_calendar")
    void truncateTable();

    @Select("SELECT SUM(final_price) from ter_price_calendar where price_day >=#{start} and price_day < #{end} and room_id =#{roomId}")
    int selectTotalPrice(Long roomId, LocalDate start , LocalDate end);
}
